<!-- 登录页面 -->
<template>
  <div>
    <div class="w-full h-screen">
      <ElForm ref="formRef" :model="formData" :rules="formRules" class="">
        <div class="font-bold py-5 text-center text-xl text-red">
          注册oil-wiki
        </div>
        <ElFormItem prop="account" class="mt-2">
          <ElInput
            v-model="formData.account"
            prefix-icon="el-icon-user-solid"
            placeholder="账号"
          />
        </ElFormItem>

        <ElFormItem prop="password">
          <ElInput
            v-model="formData.password"
            prefix-icon="el-icon-lock"
            type="password"
            :show-password="true"
            placeholder="密码"
          />
        </ElFormItem>

        <ElFormItem prop="confirmPassword">
          <ElInput
            v-model="formData.confirmPassword"
            prefix-icon="el-icon-lock"
            type="password"
            :show-password="true"
            placeholder="确认密码"
          />
        </ElFormItem>

        <ElFormItem prop="name">
          <ElInput
            v-model="formData.name"
            prefix-icon="el-icon-user"
            placeholder="用户昵称"
            @keyup.enter.native="submit"
          />
        </ElFormItem>
        <div class="flex justify-end">
          <ElButton type="text" size="mini" @click="showLogin"
            >已有账号？去登录</ElButton
          >
        </div>

        <ElButton
          type="primary"
          style="width: 100%"
          class="mt-2"
          @click="submit"
          @keyup.enter.native="submit"
          :loading="btnLoading"
        >
          确认注册
        </ElButton>
      </ElForm>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ElForm, ElFormItem, ElInput, ElButton } from "element-plus"
import { useRouter } from "vue-router"
import useState from "./hooks/useState"
import useSubmit from "./hooks/useSubmit"
const router = useRouter()
const { btnLoading, formRef, formData, formRules } = useState()
const { submit } = useSubmit({ formData, formRef, btnLoading })
const showLogin = () => {
  router.push("login")
}
</script>

<style lang="scss" scoped>
.el-form {
  @apply px-5 py-5 w-full md:w-2/5 lg:w-1/5 bg-white shadow-lg sm:mt-32 m-auto;
}
</style>
